using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine;

namespace Editor.OpenShaderInVSCode
{
    public class OpenShaderInVSCode
    {
        [OnOpenAsset(0)]
        public static bool step1(int instanceID, int line)
        {
            string path = AssetDatabase.GetAssetPath(EditorUtility.InstanceIDToObject(instanceID));
            string name = Application.dataPath + "/" + path.Replace("Assets/", "");
            if (name.EndsWith(".shader"))    //文件扩展名类型
            {
                System.Diagnostics.Process process = new System.Diagnostics.Process();
                System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                startInfo.FileName = "C:/Users/Administrator/AppData/Local/Programs/Microsoft VS Code/Code.exe";   //VSCODE程序
                startInfo.Arguments = "\"" + name + "\"";
                //startInfo.Arguments = name;
                process.StartInfo = startInfo;
                process.Start();
                return true;
            }

            return false;
        }


        [MenuItem("Tools/启用VSCode编辑Shader文件")]
        public static void OpenVSCode()
        {
            UnityEditor.Compilation.CompilationPipeline.RequestScriptCompilation();
        }
    }
}